package cn.audit.repository.operation;

import cn.audit.bean.dto.UserCorrelation;
import cn.audit.bean.pojo.Taskocation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author: fei人类
 * @Date: 2019/5/24 14:31
 */
public interface TaskocationRepository extends JpaRepository<Taskocation,Long>, JpaSpecificationExecutor<Taskocation> {

    /**
     * 审计方案人员分配
     */
    @Modifying(clearAutomatically = true)
    @Query("update Taskocation t " +
            "set t.person = ?2 " +
            "where t.id in ?1 ")
    void updateItem(List<Long> id, Long userId);

    @Query("select new cn.audit.bean.dto.UserCorrelation(u,t) " +
            "from User u,Taskocation t " +
            "where t.id in ?1 and u.id=t.person ")
    List<UserCorrelation> findAllByIdIsUser(List<Long> id);
}
